package com.such.kit.web.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.such.kit.easyparam.ParamMap;
import com.such.kit.validate.ValidateCommons;

/**
 * @author SUCH
 * <pre>
 * 为前端制定的分页对象
 * </pre>
 */
public class WebPage<T> extends WebResponse<T> implements Serializable {

	private static final long serialVersionUID = -512841773837567764L;

	/** items：此页数据集 */
	private List<T> items;
	/** total：数据总量 */
	private int total;

	public WebPage(List<T> items) {
		if (ValidateCommons.isEmpty(items)) {
			items = new ArrayList<T>();
		}
		this.items = items;
		this.total = items.size();
	}

	public WebPage(List<T> items, int total) {
		if (ValidateCommons.isEmpty(items)) {
			items = new ArrayList<T>();
		}
		this.items = items;
		this.total = total;
	}

	/** [参考 {@link #items}] */
	public List<T> getItems() {
		return this.items;
	}

	/** [参考 {@link #items}] */
	public void setItems(List<T> items) {
		this.items = items;
	}

	/** [参考 {@link #total}] */
	public int getTotal() {
		return this.total;
	}

	/** [参考 {@link #total}] */
	public void setTotal(int total) {
		this.total = total;
	}

	public Object getResponseBody() {
		return new ParamMap<String, Object>()
				.putParam("items", items)
				.putParam("total", total);
	}

}
